﻿using System;
using Coder.Workflow;
using Fee.Orders.AuthProjectWorkflow;
using Fee.Orders.DesignWorkflow;
using Fee.Orders.FormalWorkflow;
using Fee.Orders.PreWorkflow;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace Fee.Orders
{
    public class FeeWorkflowNumberGenerator : WorkflowNumberGenerator
    {
        protected override int ToIndex(string number, EntityEntry entry)
        {
            return Convert.ToInt32(number.Substring(9).TrimStart('0'));
        }

        protected override string GeneratorNumber(int index, EntityEntry entry)
        {
            var prefix = "B";
            if (entry.Entity is BudgetOrder) prefix = "B";
            else if (entry.Entity is PreDelegateOrder) prefix = "Y";
            else if (entry.Entity is FormalOrder)
            {
                prefix = "F";
            }
            else if (entry.Entity is AuthProjectOrder)
            {
                prefix = "W";
            }
            return $"{prefix}{DateTime.Today:yyyyMMdd}{index.ToString().PadLeft(5, '0')}";
        }
    }
}